package com.hd.trans.config

import androidx.appcompat.app.AppCompatActivity
import com.hd.trans.homefun.EventCode
import com.hd.trans.limit4Use.LimitUseListener
import com.hd.trans.track.TrackerListener
import com.hd.trans.ui.component.RecordFileCallback
import com.hd.trans.utils.LogUtil
import com.hd.trans.utils.PermissionCallback

class CallbackProperty {
    var trackerListener: TrackerListener  =
        object : TrackerListener {
            override fun view(title: String) {
                LogUtil.d("视图事件: $title")
            }

            override fun count(title: String, name: String) {
                LogUtil.d("统计事件: title=$title, name=$name")
            }

            override fun click(title: String, name: String) {
                LogUtil.d("点击事件: title=$title, name=$name")
            }

            override fun click(title: String, tableName: String, name: String) {
                LogUtil.d("点击事件: title=$title, tableName=$tableName, name=$name")
            }
        }
    var recordFileCallback: RecordFileCallback =
        object : RecordFileCallback {
            override fun createRecordFile(taskId: String) {}
            override fun writeByteToFile(bytes: ByteArray) {}
            override fun savePcmToWav(taskId: String) {}
            override fun saveRecord(
                taskId: String,
                origCode: String,
                transCode: String,
                origContent: String,
                transContent: String
            ) {
            }
        }

    var limitUseListener: LimitUseListener =
        object : LimitUseListener {
            override fun getFreeTrialCount(eventCode: EventCode): Int {
                return 5
            }

            override fun getFreeTrialTime(eventCode: EventCode): Long {
                return 1000 * 60 * 1
            }

            override fun isAllowTransit(eventCode: EventCode): Boolean {
                //true 表示会员
                return false
            }

            override fun intercept(
                eventCode: EventCode,
                title: String?,
                name: String?,
                tab: String?
            ) {
                //执行拦截处理
                LogUtil.d("eventName=" + eventCode.eventName + ", title=" + title + ", name=" + name + ", tab=" + tab)
            }

            override fun interceptPermission(
                activity: AppCompatActivity,
                eventCode: EventCode,
                permissions: Array<String>,
                callback: PermissionCallback?
            ): Boolean {
                //false 表示不拦截处理
                return false
            }
        }

    class Builder {
        private val property = CallbackProperty()

        fun build(): CallbackProperty {
            return property
        }

        fun setTrackerListener(trackerListener: TrackerListener): Builder {
            property.trackerListener = trackerListener
            return this
        }

        fun setRecordFileCallback(recordFileCallback: RecordFileCallback): Builder {
            property.recordFileCallback = recordFileCallback
            return this
        }

        fun setLimitUseListener(limitUseListener: LimitUseListener): Builder {
            property.limitUseListener = limitUseListener
            return this
        }
    }
}